package com.miyake.dsp.filter;

import java.util.ArrayList;
import java.util.List;

import com.miyake.dsp.filter.FilterSetting.FilterAlgo;
import com.miyake.dsp.filter.FilterSetting.FilterType;
import com.miyake.dsp.osa.lab.LabUiAnnotation;

public class FilterSetting {
	interface FilterSettingHandler {
		void onFilterAlgoChange(FilterAlgo filterAlgo);
	};
	List<FilterSettingHandler> handlers;
		
	void addHandler(FilterSettingHandler handler) {
		if (handlers == null) {
			handlers = new ArrayList<FilterSettingHandler>();
		}
		handlers.add(handler);
	}
	private void fireFilterAlgoChange(FilterAlgo filterAlgo) {
		if (handlers == null)return;
		
		for (FilterSettingHandler h : handlers) {
			h.onFilterAlgoChange(filterAlgo);
		}
	}
	public enum FilterAlgo {
		Butterworth, Chebyshev1, Chebyshev2, Elliptic, Fir
	};
	
	public enum FilterType {
		Lowpass, Highpass, Bandpass, Stopband
	};
	
	public enum WindowType {
		Rectangle, Triangle, Hamming, Hanning, Kaiser, Chebyshev
	};
	
	@LabUiAnnotation(caption="Filter Algorythm")
	private FilterAlgo filterAlgo = FilterAlgo.Butterworth;
	@LabUiAnnotation(caption="Filter Type")
	private FilterType filterType = FilterType.Lowpass;
	@LabUiAnnotation(caption="Window Type")
	private WindowType windowType = WindowType.Rectangle;
	@LabUiAnnotation(caption="Cutoff Low")
	private double cutoff1;
	@LabUiAnnotation(caption="Cutoff High")
	private double cutoff2;
	@LabUiAnnotation(caption="Order")
	private int order;
	@LabUiAnnotation(caption="Smp. Freq.")
	private double frequency;
	@LabUiAnnotation(caption="Delta 1")
	private double delta1 = 0.1;
	@LabUiAnnotation(caption="Delta 2")
	private double delta2 = 0.1;
	
	public FilterSetting() {
	}
	
	public FilterSetting(FilterAlgo algo, FilterType type, int order, double cutoff) {
		this.filterAlgo = algo;
		this.filterType = type;
		this.order = order;
		if (this.filterType.equals(FilterType.Lowpass)) {
			this.cutoff1 = cutoff;
		}
		else if (this.filterType.equals(FilterType.Highpass)) {
			this.cutoff2 = cutoff;
		}
	}

	public FilterAlgo getFilterAlgo() {
		return filterAlgo;
	}
	
	public void setFilterAlgo(FilterAlgo filterAlgo) {
		this.filterAlgo = filterAlgo;
		fireFilterAlgoChange(filterAlgo);
	}
	public FilterType getFilterType() {
		return filterType;
	}
	public void setFilterType(FilterType filterType) {
		this.filterType = filterType;
	}
	public double getCutoff1() {
		return cutoff1;
	}
	public void setCutoff1(double cutoff1) {
		this.cutoff1 = cutoff1;
	}
	public double getCutoff2() {
		return cutoff2;
	}
	public void setCutoff2(double cutoff2) {
		this.cutoff2 = cutoff2;
	}
	public int getOrder() {
		return order;
	}
	public void setOrder(int order) {
		this.order = order;
	}
	public double getFrequency() {
		return frequency;
	}
	public void setFrequency(double frequency) {
		this.frequency = frequency;
	}
	public double getDelta1() {
		return delta1;
	}
	public void setDelta1(double delta1) {
		this.delta1 = delta1;
	}
	public double getDelta2() {
		return delta2;
	}
	public void setDelta2(double delta2) {
		this.delta2 = delta2;
	}
	public WindowType getWindowType() {
		return windowType;
	}
	public void setWindowType(WindowType windowType) {
		this.windowType = windowType;
	}
	
	
}
